{% block sw_newsletter_recipient_list %}
<sw-page class="sw-newsletter-recipient-list">
    {% block sw_newsletter_recipient_list_search_bar %}
    <template #search-bar>
        <sw-search-bar
            initial-search-type="newsletter_recipient"
            :placeholder="$tc('sw-newsletter-recipient.general.placeholderSearchBarSnippets')"
            :initial-search="term"
            @search="onSearch"
        />
    </template>
    {% endblock %}

    {% block sw_newsletter_recipient_list_smart_bar_header %}
    <template #smart-bar-header>
        {% block sw_newsletter_recipient_list_smart_bar_header_title %}
        <h2>
            {% block sw_newsletter_recipientlist_list_smart_bar_header_title_text %}
            {{ $tc('global.sw-admin-menu.navigation.mainMenuItemMarketing') }}
            <mt-icon
                name="regular-chevron-right-xs"
                size="12px"
            />
            {{ $tc('sw-newsletter-recipient.list.textHeadline') }}
            {% endblock %}

            {% block sw_newsletter_recipient_list_smart_bar_header_amount %}
            <span
                v-if="!isLoading"
                class="sw-page__smart-bar-amount"
            >
                ({{ total }})
            </span>
            {% endblock %}
        </h2>
        {% endblock %}
    </template>
    {% endblock %}

    {% block sw_newsletter_recipientlist_list_content %}
    <template #content>
        {% block sw_newsletter_recipientlist_list_content_card %}
        {% block sw_newsletter_recipientlist_list_grid %}
        <sw-entity-listing
            v-if="items && entitySearchable"
            ref="swNewsletterRecipientGrid"
            class="sw-newsletter-recipient-list__grid"
            :is-loading="isLoading"
            identifier="sw-newsletter-recipient"
            :show-selection="false"
            :items="items"
            :columns="columns"
            :repository="repository"
            detail-route="sw.newsletter.recipient.detail"
            :sort-by="currentSortBy"
            :sort-direction="sortDirection"
            :disable-data-fetching="true"
            :allow-view="acl.can('newsletter_recipient.viewer')"
            :allow-edit="acl.can('newsletter_recipient.editor')"
            :allow-inline-edit="acl.can('newsletter_recipient.editor')"
            :allow-delete="acl.can('newsletter_recipient.deleter')"
            @page-change="onPageChange"
            @column-sort="onSortColumn"
        >

            {% block sw_newsletter_recipientlist_list_grid_email %}
            <template #column-email="{ item }">
                <p>{{ emailIdnFilter(item.email) }}</p>
            </template>
            {% endblock %}

            {% block sw_newsletter_recipientlist_list_grid_name %}
            <template
                #column-firstName="{ item, compact, isInlineEdit }"
            >

                {% block sw_newsletter_recipientlist_list_grid_inline_edit_name %}
                <template v-if="isInlineEdit">
                    {% block sw_newsletter_recipientlist_list_grid_inline_edit_first_name %}

                    <mt-text-field
                        v-model="item.firstName"
                        class="sw-newsletter-recipient-list__inline-edit-first-name"
                        :size="compact ? 'small' : 'default'"
                    />
                    {% endblock %}

                    {% block sw_newsletter_recipientlist_list_grid_inline_edit_last_name %}

                    <mt-text-field
                        v-model="item.lastName"
                        class="sw-newsletter-recipient-list__inline-edit-last-name"
                        :size="compact ? 'small' : 'default'"
                    />
                    {% endblock %}
                </template>
                {% endblock %}

                {% block sw_newsletter_recipientlist_list_grid_name_link %}
                <template v-else>
                    {{ item.firstName }} {{ item.lastName }}
                </template>
                {% endblock %}
            </template>
            {% endblock %}

            {% block sw_newsletter_recipientlist_list_grid_status %}
            <template
                #column-status="{ item, compact, isInlineEdit }"
            >
                {% block sw_newsletter_recipientlist_list_grid_status_notSet %}
                <template v-if="item.status === 'notSet'">
                    <sw-label
                        size="medium"
                        appearance="pill"
                    >
                        {{ $tc('sw-newsletter-recipient.list.notSet') }}
                    </sw-label>
                </template>
                {% endblock %}
                {% block sw_newsletter_recipientlist_list_grid_status_optIn %}
                <template v-else-if="item.status === 'optIn'">
                    <sw-label
                        size="medium"
                        appearance="pill"
                    >
                        {{ $tc('sw-newsletter-recipient.list.optIn') }}
                    </sw-label>
                </template>
                {% endblock %}
                {% block sw_newsletter_recipientlist_list_grid_status_optOut %}
                <template v-else-if="item.status === 'optOut'">
                    <sw-label
                        size="medium"
                        appearance="pill"
                    >
                        {{ $tc('sw-newsletter-recipient.list.optOut') }}
                    </sw-label>
                </template>
                {% endblock %}
                {% block sw_newsletter_recipientlist_list_grid_status_direct %}
                <template v-else-if="item.status === 'direct'">
                    <sw-label
                        size="medium"
                        appearance="pill"
                    >
                        {{ $tc('sw-newsletter-recipient.list.direct') }}
                    </sw-label>
                </template>
                {% endblock %}
            </template>
            {% endblock %}

            {% block sw_newsletter_recipientlist_list_grid_updated_at %}
            <template
                #column-updatedAt="{ item }"
            >
                {{ dateFilter(item.updatedAt) }}
            </template>
            {% endblock %}

            {% block sw_newsletter_recipientlist_list_grid_created_at %}
            <template
                #column-createdAt="{ item }"
            >
                {{ dateFilter(item.createdAt) }}
            </template>
            {% endblock %}

        </sw-entity-listing>

        {% block sw_newsletter_recipient_list_empty_state %}
        <template v-if="!isLoading && !total">
            <sw-empty-state
                v-if="isValidTerm(term)"
                :title="$tc('sw-empty-state.messageNoResultTitle')"
            >
                <template #default>
                    {{ $tc('sw-empty-state.messageNoResultSublineBefore') }}
                    <router-link
                        class="sw-empty-state__description-link"
                        :to="{ name: 'sw.profile.index.searchPreferences' }"
                    >
                        {{ $tc('sw-empty-state.messageNoResultSublineLink') }}
                    </router-link>
                    {{ $tc('sw-empty-state.messageNoResultSublineAfter') }}
                </template>
            </sw-empty-state>

            <sw-empty-state
                v-else
                :title="$tc('sw-newsletter-recipient.list.messageEmpty')"
            />
        </template>
        {% endblock %}
        {% endblock %}
        {% endblock %}
    </template>
    {% endblock %}

    {% block sw_newsletter_recipient_list_sidebar %}
    <template #sidebar>
        <sw-sidebar>
            {% block sw_newsletter_recipient_list_sidebar_refresh %}
            <sw-sidebar-item
                icon="regular-undo"
                :title="$tc('sw-newsletter-recipient.list.titleSidebarItemRefresh')"
                @click="onRefresh"
            />
            {% endblock %}

            {% block sw_newsletter_recipient_list_sidebar_filter %}
            <sw-sidebar-item
                ref="filterSideBar"
                icon="regular-filter"
                :title="$tc('sw-newsletter-recipient.list.titleSidebarItemFilter')"
                @sw-sidebar-item-close-content="closeContent"
                @click="closeContent"
            >

                {% block sw_newsletter_recipient_list_sidebar_filter_status %}
                <sw-sidebar-collapse>
                    <template #header>
                        {{ $tc('sw-newsletter-recipient.list.status') }}
                    </template>
                    <template #content>
                        {% block sw_newsletter_recipient_list_sidebar_filter_status_not_set %}
                        <sw-newsletter-recipient-filter-switch
                            id="notSet"
                            group="status"
                            :label="$tc('sw-newsletter-recipient.list.notSet')"
                            @update:value="onChange"
                        />
                        {% endblock %}
                        {% block sw_newsletter_recipient_list_sidebar_filter_status_direct %}
                        <sw-newsletter-recipient-filter-switch
                            id="direct"
                            group="status"
                            :label="$tc('sw-newsletter-recipient.list.direct')"
                            @update:value="onChange"
                        />
                        {% endblock %}
                        {% block sw_newsletter_recipient_list_sidebar_filter_status_opt_in %}
                        <sw-newsletter-recipient-filter-switch
                            id="optIn"
                            group="status"
                            :label="$tc('sw-newsletter-recipient.list.optIn')"
                            @update:value="onChange"
                        />
                        {% endblock %}
                        {% block sw_newsletter_recipient_list_sidebar_filter_status_opt_out %}
                        <sw-newsletter-recipient-filter-switch
                            id="optOut"
                            group="status"
                            :label="$tc('sw-newsletter-recipient.list.optOut')"
                            @update:value="onChange"
                        />
                        {% endblock %}
                    </template>
                </sw-sidebar-collapse>
                {% endblock %}

                {% block sw_newsletter_recipient_list_sidebar_filter_language %}
                <sw-sidebar-collapse>
                    <template #header>
                        {{ $tc('sw-newsletter-recipient.general.language') }}
                    </template>
                    <template #content>
                        {% block sw_newsletter_recipient_list_sidebar_filter_language_items %}
                        <div
                            v-for="(item, index) in languageFilters"
                            :key="index"
                        >
                            <sw-newsletter-recipient-filter-switch
                                :id="item.id"
                                group="languageId"
                                :label="item.name"
                                @update:value="onChange"
                            />
                        </div>
                        {% endblock %}
                    </template>
                </sw-sidebar-collapse>
                {% endblock %}

                {% block sw_newsletter_recipient_list_sidebar_filter_sales_channel %}
                <sw-sidebar-collapse>
                    <template #header>
                        {{ $tc('sw-newsletter-recipient.general.salesChannel') }}
                    </template>
                    <template #content>
                        {% block sw_newsletter_recipient_list_sidebar_filter_sales_channel_items %}
                        <div
                            v-for="(item, index) in salesChannelFilters"
                            :key="index"
                        >
                            <sw-newsletter-recipient-filter-switch
                                :id="item.id"
                                group="salesChannelId"
                                :label="item.translated.name"
                                @update:value="onChange"
                            />
                        </div>
                        {% endblock %}
                    </template>
                </sw-sidebar-collapse>
                {% endblock %}

                {% block sw_newsletter_recipient_list_sidebar_filter_sales_tags %}
                <sw-sidebar-collapse>
                    <template #header>
                        {{ $tc('sw-newsletter-recipient.general.tags') }}
                    </template>
                    <template #content>
                        {% block sw_newsletter_recipient_list_sidebar_filter_sales_tags_select %}
                        <sw-entity-multi-select
                            v-model:entity-collection="tagCollection"
                            @update:entity-collection="onChange"
                        />
                        {% endblock %}
                    </template>
                </sw-sidebar-collapse>
                {% endblock %}
            </sw-sidebar-item>
            {% endblock %}

        </sw-sidebar>
    </template>
    {% endblock %}
</sw-page>
{% endblock %}
